﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cypher.Core.Configuration
{
	public class ServiceElementCollection : System.Configuration.ConfigurationElementCollection
	{
		#region Constructor(s)

		public ServiceElementCollection()
			: base(StringComparer.OrdinalIgnoreCase)
		{
			this.AddElementName = "service";
		}

		#endregion

		#region Properties

		public ServiceElement this[int index]
		{
			get
			{
				return (ServiceElement)base.BaseGet(index);
			}
			set
			{
				if (base.BaseGet(index) != null)
				{
					base.BaseRemoveAt(index);
				}
				this.BaseAdd(index, value);
			}
		}

		public new ServiceElement this[string key]
		{
			get
			{
				return (ServiceElement)base.BaseGet(key);
			}
		}

		#endregion

		#region Overrides

		protected override System.Configuration.ConfigurationElement CreateNewElement()
		{
			return new ServiceElement();
		}

		protected override object GetElementKey(System.Configuration.ConfigurationElement element)
		{
			return ((ServiceElement)element).Name;
		}

		#endregion
	}
}
